package org.datastealer.controller;

import org.datastealer.bean.Column;
import org.datastealer.bean.Table;
import org.datastealer.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Note：
 *
 * @author ：mengjw
 * @description：数据库Table控制层
 * @date ：Created in 2020/8/23
 */
@RestController
@RequestMapping("/datastealer")
public class TableController {

    @Autowired
    private TableService tableService;

    @GetMapping("/schema/{schemaName}/table")
    public List<Table> getTablesBySchema(@PathVariable String schemaName) {
        return tableService.getTablesBySchema(schemaName);
    }

    @GetMapping("/schema/{schemaName}/table/{tableName}/ddl")
    public String getTableDDL(@PathVariable String schemaName, @PathVariable String tableName) {
        return tableService.getTableDDL(schemaName, tableName);
    }

    @GetMapping("/schema/{schemaName}/table/{tableName}/column")
    public List<Column> getTableColumns(@PathVariable String schemaName, @PathVariable String tableName) {
        return tableService.getTableColumns(schemaName, tableName);
    }

    @GetMapping("/schema/{schemaName}/table/{tableName}/data")
    public List<Map<String, Object>> getDataByPage(@PathVariable String schemaName, @PathVariable String tableName,
                                                   @RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        return tableService.getDataByPage(schemaName, tableName, pageNum, pageSize);
    }
}